package exercise;

class Solution11 {
    public int longestOnes(int[] nums, int k) {
        int ans = 0, l = 0, r = 0, n = nums.length;
        while (r < n) {
            if (nums[r] == 0) {
                k--;
            }
            while (k < 0) {
                if (nums[l++] == 0) {
                    k++;
                }
            }
            ans = Math.max(ans, r-l+1);
            r++;
        }
        return ans;
    }
}